package gspushmq.v1.main;

import java.io.File;

import ggframework.mongodb.BasicDBObject;
import ggframework.mongodb.DBCollection;
import ggframework.util.GGConfigurer;
import ggjob.job.Bootstrap;
import gspushmq.util.GGSystemUtil;
import gspushmq.util.MongoUtil;
import gspushmq.v1.thread.GGThreadPoolBuilder;
import gspushmq.v1.websocket.core.GGWebSocketBuilder;

/**
 * 系统初始化
 * 
 * @version 1.0
 * @since JDK1.7
 * @author Albert
 * @company 上海朝阳永续信息技术股份有限公司
 * @copyright (c) 2016 SunTime Co'Ltd Inc. All rights reserved.
 * @date 2016年5月10日 下午9:18:51
 */
public class EngineMes {
	public static void main(String[] args) {
		Bootstrap.init("config/config.properties", true);
		if(GGConfigurer.getBoolean("ggpush.iswritepid", false)){
			File root = new File(GGConfigurer.get("ggpush.path", "./"));
			GGSystemUtil.writePID(root);
		}
		//启动线程池
		GGThreadPoolBuilder.start();
		GGWebSocketBuilder.start();
		//生产程序-job
		GGPushEngineMesJob.start();
		
		//生产程序-mq
		GGRabbitMQEnable.start();
		//推送程序
		GGHandlerAndSendMQ.start();
	}
	
	public static void close() {
		//销毁线程池
		GGThreadPoolBuilder.destory();
		GGWebSocketBuilder.destory();
		GGRabbitMQEnable.destory();
//		GGPushCountJob.close();
	}

	public static void  init(){
		DBCollection messRecord = MongoUtil.getFtAccountBehaviorCollection("cbs_msg_storage_record");
		messRecord.remove(new BasicDBObject());
		DBCollection messSendRecord = MongoUtil.getFtAccountBehaviorCollection("cabs_msg_send_record");
		messSendRecord.remove(new BasicDBObject());
		DBCollection collection = MongoUtil.getFtMixCollection("cs_msg_define");
		collection.remove(new BasicDBObject());

	}

}
